include<tools/util.scad>

$fn=100;

//motor_shelf();
//translate([0,80,0])plate();
//translate([50,-50,0])speed_lid();
//translate([-60,0,0])fastening();
//translate([0,-80,0])
moto_link();

module motor_shelf(){

            //电机架
            difference(){
                cube([35,25,32]);
                translate([3.5,-1,5])cube([21.5,31,66]);
                translate([-1,4,5])cube([39,18.6,60]);
                //电机固定孔
                translate([30,29,7.75])rotate([90,0,0])cylinder(h=30,d=3);
                translate([30,29,25.25])rotate([90,0,0])cylinder(h=30,d=3);        
            }
            //增高条
            translate([-15,-10,0])difference(){
                
                cube([80,14,32]);
                translate([18.5,-0.5,5])cube([31.5,15,33]);
                translate([-0.5,5,-0.5])cube([15.5,10,33]);
                translate([54.5,5,-0.5])cube([26.5,10,33]);
                translate([54.5,0,22])cube([26.5,5,15]);
                //安装固定孔
                translate([7,6,15])rotate([90,0,0])cylinder(h=7,d=5);
                translate([70,6,10])rotate([90,0,0])cylinder(h=7,d=5);
                
            }
            //调速器架
            translate([99.5,-10,0])rotate([0,0,90])speed_box();
 
    
}

module speed_box(){
    difference(){
        cube([35,34.5,19]);
        translate([1,1,2])cube([33,32.5,18]);
        translate([12,0,2])cube([10,5,18]);
        translate([7,31,2])cube([20,5,18]);       
    }
    translate([33,15,2])cube([1,3,10]);

}
module speed_lid(){
    //调速器盖子
    pos=[[0.8,10],[0.8,20],[32.8,10],[32.8,20]];

    cube([35,34.5,1.5]);
    for(i=[0:3]){
        translate([pos[i][0],pos[i][1],1.5])cube([1.4,2,3]);
    }
}
module fastening(){
    //固定件
    for(i=[0:15:15]){
        translate([i,0,0])d_fastening_pair(rod_len=30,rod_diam=4.6,cap_diam=9,cap_height=2);
    
    
    //电机固定销
    translate([i,-35,0])d_fastening_pair(rod_len=34,rod_diam=2.6,cap_diam=10,cap_height=1,nut_height=4);
    }
    /*
     translate([15,-35,0])d_fastening_pair(rod_len=34,rod_diam=2.6,cap_diam=10,cap_height=1,nut_height=4);
*/
}

module plate(){
    plate_diam=80;
    cylinder(h=1.5,d=plate_diam);
    translate([0,0,1.5])difference(){
        cylinder(h=25,d=68);
        cylinder(h=26,d=64.5);
    }
}
module moto_link(){
    difference(){
        cylinder(h=5,d=64.3);
        cylinder(h=5.5,d=58);
    }
    difference(){
        union(){
            translate([0,0,2.5])union(){
                cube([59,4,5],center=true);
                cube([4,59,5],center=true);
            }
            cylinder(h=27,d=14);
        }
        translate([0,0,24])intersection(){
            cube([5.6,3.9,6.1],center=true);
            translate([0,0,-3])cylinder(h=6.1,d=5.6);
        }
    }
    
}
